﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HoneyBadgersOfficePlayer.Models;

namespace HoneyBadgersOfficePlayer.Views
{
    public partial class Profile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Globals.IsAdmin != 1)
            {
                //NavigationMenu.Items[2].Enabled = true;
                NavigationMenu.Items.RemoveAt(3);
            }

            if (!IsPostBack)
            {
                
                List<SqlParameter> parameterList = new List<SqlParameter>();
                parameterList.Add(new SqlParameter("@User_id", Globals.UserID));
                SqlDataReader reader = SQLUtilities.RunStoredProcedure("GetUserInfo", parameterList);

                if (reader != null)
                {
                    while (reader.Read())
                    {
                        First_Name.Text = reader[0].ToString();
                        Last_Name.Text = reader[1].ToString();
                        Username.Text = "Username: " + reader[2].ToString();
                        User_Email.Text = reader[3].ToString();
                        Address.Text = reader[4].ToString();
                        City.Text = reader[5].ToString();
                        State.Text = reader[6].ToString();
                        ZipCode.Text = reader[7].ToString();
                        if (reader[8].ToString() == "True")
                        {
                            Explicit.Checked = true;
                        }
                    }
                }

                parameterList.Clear();
                parameterList.Add(new SqlParameter("@User_id", Globals.UserID));
                SqlDataReader reader2 = SQLUtilities.RunStoredProcedure("GetUsersSongRating", parameterList);

                if (reader2 != null)
                {
                    ////shellies code
                    DataTable dt = new DataTable();
                    ////jestins code
                    BoundField bf = new BoundField();
                    BoundField bf1 = new BoundField();
                    BoundField bf2 = new BoundField();
                    BoundField bf3 = new BoundField();
                    BoundField bf4 = new BoundField();

                    ////shellies code
                    dt.Columns.Add("Ratings");
                    dt.Columns.Add("Artist");
                    dt.Columns.Add("Song");
                    dt.Columns.Add("Genre");
                    dt.Columns.Add("SongID");

                    while (reader2.Read())
                    {

                        ////shellies code
                        string songID = reader2[4].ToString();
                        string rating = reader2[2].ToString();
                        string artist = reader2[0].ToString();
                        string song = reader2[1].ToString();
                        string genre = reader2[3].ToString();
                        
                        
                        
                        
                        //dt.Rows.Add(rating, artist, song, genre, songID);
                        dt.Rows.Add( 
                        bf1.DataField.Insert(0, rating),
                        bf2.DataField.Insert(0, artist),
                        bf3.DataField.Insert(0, song),
                        bf4.DataField.Insert(0, genre),
                        bf.DataField.Insert(0, songID)
                        );
                        
                    }
                    Session["CACHEDATA1"] = dt;
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
            }
        }

        protected void Update_Info_Button_Click(object sender, EventArgs e)
        {
            List<SqlParameter> parameterList = new List<SqlParameter>();
            parameterList.Add(new SqlParameter("@user_id", Globals.UserID));
            parameterList.Add(new SqlParameter("@Address", Address.Text));
            parameterList.Add(new SqlParameter("@First_Name", First_Name.Text));
            parameterList.Add(new SqlParameter("@Last_Name", Last_Name.Text));
            parameterList.Add(new SqlParameter("@User_Email", User_Email.Text));
            if (Explicit.Checked == true)                                                  
                parameterList.Add(new SqlParameter("@explicit", 1));
            else
                parameterList.Add(new SqlParameter("@explicit", 0));
            parameterList.Add(new SqlParameter("@CityName", City.Text));
            parameterList.Add(new SqlParameter("@StateName", State.Text));
            parameterList.Add(new SqlParameter("@Zip_Code", ZipCode.Text));

            SQLUtilities.RunStoredProcedure("Update_User", parameterList);
        }

    }
}